<?php

namespace App\Http\Controllers\AjaxRequest;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Input;
use Redirect;

class UpdateController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */

    public function index()
    {
         //echo "1234";
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  Request  $request
     * @return Response
     */

    public function store(Request $request)
    {
           // $id=Input::get('id');
            $url  =     $_SERVER['HTTP_REFERER'];
            $userid = explode('?',$url);
            $id= explode('=', $userid[1]);
            $realname =$request->input('I_Name');
            $gender = $request->input('gender');
            $cellphone = $request->input('I_tel');
            $area = $request->input('I_Area');
            $email =  $request->input('I_Email');
             $json_arr = array("userid"=>$id[1],"realname"=>$realname,"gender"=>$gender,"cellphone"=>$cellphone,"area"=>$area,"email"=>$email);
           $o="";
            foreach ($json_arr as $k=>$v)
            {
                 $o.= "$k=".urlencode($v)."&";
            }
           $json_data=substr($o,0,-1);
           $url =  "192.168.0.21:8080/test/user/info";
             $ch = curl_init();
            curl_setopt($ch,CURLOPT_URL,$url); /*获取URL的内容*/
           curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"PUT");
            curl_setopt($ch, CURLOPT_POSTFIELDS,$json_data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);/*获取的内容不输出*/
           $content = curl_exec($ch);/*输出获取的内容*/
           $obj=json_decode($content);
            $obj=json_decode($content);
            if(empty($obj->error)){
                return Redirect::to("update?id=".$id[1]);
             }else{
                  return Redirect::back()->withInput()->withErrors(' 更新失败');
       }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  Request  $request
     * @param  int  $id
     * @return Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *su
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        //
    }
}
?>